home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 50-CommHardware / isdn / isdn-setup.frm.z / isdn-setup.frm
Encoding:
Text File  |  2002-06-12  |  8.5 KB  |  303 lines

  1. #!/usr/bin/perl5
  2. #
  3. # isdn.cgi 
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: isdn-setup.frm,v 1.42 1998/02/11 23:14:13 jrw Exp $
  21.  
  22. # currently allowed only one switch type (and pair of SPID #'s),
  23. # but can have multiple connection names (and phone numbers).
  24. # this is to remove ambiguity that entries in isdnd.options know
  25. # nothing of connection names.  code will comment out conflicting
  26. # entries.
  27.  
  28. require "/usr/OnRamp/lib/OnRamp.pm";
  29. require "/usr/OnRamp/lib/java.pm";
  30.  
  31. $confS = "/etc/uucp/Systems";
  32. $conf = "/etc/config/isdnd.options";
  33. $dummy = "/etc/config/isdnd.options.tmp";
  34. $pwdfile = "/etc/passwd";
  35. $myname = "isdn-setup.cgi";
  36. $help_page = "isdn-setup-help.html";
  37. $title = "ISDN Setup";
  38.  
  39. if ($ENV{'HTTP_USER_AGENT'} =~ /Mozilla\/2/) { $br_index = 1; }
  40. else { $br_index = 0; }
  41.  
  42. $js =
  43. "br_index = $br_index;
  44. $js_standard
  45. $js_error_box
  46. $js_help
  47. $js_phone
  48. $js_hostname
  49. function checkForm(form) {
  50.     if (form.isdns[br_index].checked) {
  51.         if (!testHostname(form.nme, form.nme.value, \"connection name\", 0)) return (false);
  52.         if (!testPhone(form.phone)) return (false);
  53.         if (!testSwitch(form)) return (false);
  54.     } return (true);
  55. }
  56. function testSwitch(form) {
  57.     Ctrl = form.switchtype; selnum = Ctrl.selectedIndex;
  58.     word1 = form.spid1.value; word2 = form.spid2.value;
  59.     selected = Ctrl.options[selnum].text;
  60.     if (selected == \"DMS100\" || selected == \"NI1\") {
  61.         if(word1 == \"\" || word2 == \"\") { 
  62.             errorBox (Ctrl, \"Two SPID numbers required for \\nswitch type \" + selected); 
  63.             return (false); 
  64.         }
  65.         for(i=0; i < word1.length; i++) { 
  66.             if (! checkInt_c(word1.charAt(i), 10)) {
  67.                 errorBox (Ctrl, \"Invalid SPID number: \" + word1); 
  68.                 return (false); 
  69.             } 
  70.         }
  71.         for(i=0; i < word2.length; i++) { 
  72.             if (! checkInt_c(word2.charAt(i), 10)) {
  73.                 errorBox (Ctrl, \"Invalid SPID number: \" + word2); 
  74.                 return (false); 
  75.             } 
  76.         }
  77.     } return (true);
  78. }";
  79.  
  80.  
  81. print "Content-type: text/html\n\n";
  82.  
  83. @types = ('DMS100','NI1','5ESS','NTT','NET3/DSS1','1TR6','VN3','TPH');
  84.  
  85. &get_fields;
  86.  
  87. &getInfo;
  88.  
  89. $help = $document_root . $ENV{"SCRIPT_NAME"};
  90. $help =~ s/cgi$/hlp/;
  91. exec $help if ($fld{'help'} eq "Help");
  92.  
  93. if ($fld{"doit"} eq "Ok") {
  94.     if ($fld{'isdns'} eq "Yes") { &formValidation; };
  95.     &edit; 
  96.     &getInfo; 
  97.     &putValues;
  98.     if (!$message) { $message = "No change."; }
  99. } else { &putValues; }
  100.  
  101. if (-e "/usr/etc/isdnd") { &generic; }
  102. else {
  103.     &title_block($title);
  104.     &header_block($title);
  105.     print "<i>ISDN software is not installed on this system.  Install 
  106.     subsystem </i><b>isdn_eoe.sw</b><i> from the distribution CD.</i>";
  107. }
  108.  
  109. sub formValidation {
  110.     &error("Invalid telephone number entry.") if &check_phone($fld{'phone'});
  111.     &error("Invalid connection name.") if $fld{'nme'} =~ /$METACHARS/o;
  112.     
  113.     if ($fld{'switchtype'} eq 'DMS100' || $fld{'switchtype'} eq 'NI1') {
  114.     &error("Invalid SPID number: $fld{'spid1'}.") 
  115.         if ($fld{'spid1'} =~ /[^0-9]/);
  116.     &error("Invalid SPID number: $fld{'spid2'}.") 
  117.         if ($fld{'spid2'} =~ /[^0-9]/);
  118.     if (!$fld{'spid1'}) 
  119.         { &error("Two SPID numbers required for this switch."); }
  120.     if (!$fld{'spid2'}) 
  121.         { &error("Two SPID numbers required for this switch."); }
  122.     }
  123. }
  124.  
  125. sub error {
  126.     &error_block($_[0]);
  127.     %val = %fld;
  128.     &generic;
  129.     exit 0;
  130. }
  131.  
  132. sub edit {
  133.     if ($fld{'isdns'} ne $isdns) { &editStatus; }
  134.     if ($fld{'isdns'} eq "Yes") { &writeFile; }
  135. }
  136.  
  137. sub writeFile {
  138.     if (&checkOpChange) {
  139.     open(IN,"< $conf");
  140.     open(OUT,"> $dummy");
  141.     while(<IN>) {
  142.         $line = $_;
  143.         if (substr($_,0,2) ne "-t") { print OUT $_; }
  144.         else { print OUT "# $line"; }
  145.     }
  146.     if ($fld{'switchtype'} eq "NET3/DSS1") {
  147.         print OUT "-t NET3";
  148.     } else {
  149.         print OUT "-t $fld{'switchtype'}";
  150.     }
  151.     if ($fld{'switchtype'} eq 'DMS100' || $fld{'switchtype'} eq 'NI1') {
  152.         print OUT " -s $fld{'spid1'} -s $fld{'spid2'}";
  153.     }
  154.     print OUT "\n";
  155.     close(OUT);
  156.     close(IN);
  157.     rename($dummy,$conf);
  158.     }
  159.  
  160.     $fld{'phone'} =~ s/-//g;
  161.     if (&checkSyChange) {
  162.     open(IN,"< $confS");
  163.     open(OUT,"> $dummy");
  164.     while(<IN>) {
  165.         @items = split(/\s+/);
  166.         if (substr($items[0],0,1) eq '#') { print OUT $_; next; }
  167.         if ($items[0] ne $nme || $items[2] ne 'ISDN') { print OUT $_; }
  168.         else { print OUT "# $_"; }
  169.     }
  170.     if ($fld{'switchtype'} eq "NET3/DSS1") {
  171.         print OUT 
  172.         qq|$fld{'nme'} Any ISDN 38400 "" "" ISDNCALL[64]$fld{'phone'} CONNECTED\n|;
  173.     } else {
  174.         print OUT 
  175.         qq|$fld{'nme'} Any ISDN 38400 "" "" ISDNCALL[56]$fld{'phone'} CONNECTED\n|;
  176.     }
  177.     close(OUT);
  178.     close(IN);
  179.     chmod 0600, $confS;
  180.     rename($dummy,$confS);
  181.     chmod 0400, $confS;
  182.     }
  183.     $message .= "Parameters edited.";
  184. }
  185.  
  186. sub checkSyChange {
  187.     if ($fld{'nme'} ne $nme || $fld{'phone'} ne $phone) { return 1; }
  188.     return 0;
  189. }
  190.  
  191. sub checkOpChange {
  192.     if ($fld{'switchtype'} ne $swType) { return 1; }
  193.     if ($swNum > 1) { return 0; }
  194.     if ($fld{'spid1'} ne $spid[0]) { return 1; }
  195.     if ($fld{'spid2'} ne $spid[1]) { return 1; }
  196.     return 0;
  197. }
  198.  
  199. sub editStatus {
  200.     if ($fld{'isdns'} eq "Yes") { 
  201.     system("/etc/chkconfig", "isdnd", "on");
  202.         `/bin/csh -c '(/bin/csh /etc/init.d/isdnd stop) >&! /dev/null'`;
  203.         `/bin/csh -c '(/bin/csh /etc/init.d/isdnd start) >&! /dev/null'`;
  204.         $message = "ISDN enabled.  ";
  205.     }
  206.     else {
  207.     system("/etc/chkconfig", "isdnd", "off");
  208.         `/bin/csh -c '(/bin/csh /etc/init.d/isdnd stop) >&! /dev/null'`;
  209.         $message = "ISDN disabled.  ";
  210.     }
  211. }
  212.  
  213. sub putValues {
  214.     $val{'isdns'} = $isdns;
  215.     $val{'nme'} = $nme;
  216.     $val{'phone'} = $phone;
  217.     $val{'switchtype'} = $swType;
  218.     $val{'spid1'} = $spid[0];
  219.     $val{'spid2'} = $spid[1];
  220. }
  221.    
  222. sub generic {
  223.     &js_title_block($title,$js);
  224.     &header_block($title);
  225.  
  226.     print "<i>$message</i>";
  227.  
  228.     print "<form name=\"StandardForm\" action=$myname method=post onSubmit=\"return runSubmit()\">\n";
  229.  
  230.     print "<center><table cellpadding=5 width=450>\n";
  231.  
  232.     print "<tr><th align=left>Enable ISDN:</th><th align=left>";
  233.     print &radio('isdns',$val{'isdns'},"Yes","No");
  234.     print "</th></tr>";
  235.  
  236.     print "<tr><th align=left>Connection name for host answering calls:
  237.         </th><th align=left>";
  238.     print &text('nme',$val{'nme'},20);
  239.     print "</th></tr>";
  240.     
  241.     print "<tr><th align=left>Phone number for host answering calls:
  242.         </th><th align=left>";
  243.     print &text('phone',$val{'phone'},20);
  244.     print "</th></tr>";    
  245.  
  246.     print "<tr><th align=left>Type of switch used for connections:
  247.         </th><th align=left>";
  248.     print &select('switchtype',$val{'switchtype'},'DMS100','NI1','5ESS',
  249.         'NTT','NET3/DSS1','1TR6','VN3','TPH');
  250.     print "</th></tr>\n";
  251.  
  252.     print "<tr><th align=left>SPID #1:</th><th align=left>";
  253.     print &text('spid1',$val{'spid1'},20);
  254.     print "</th></tr>\n";
  255.  
  256.     print "<tr><th align=left>SPID #2:</th><th align=left>";
  257.     print &text('spid2',$val{'spid2'},20);
  258.     print "</th></tr></table></center><br>\n";
  259.  
  260.     print "<i>Note: SPID numbers are required only for switch types\n";
  261.     print "DMS100 and NI1.</i><br><br>\n";
  262.  
  263.     print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"',
  264.         "onClick=\"do_help('$help_page'); return (false)\"");
  265.  
  266.     print '</form>';
  267. }
  268.  
  269. sub getInfo {
  270.     $isdns = &get_config("isdnd");
  271.     $spid[0] = $spid[1] = "";
  272.  
  273.     open(IN,"< $conf");
  274.     while(<IN>) {
  275.     $line = $_;
  276.     if (substr($line,0,2) eq "-t") {
  277.         @args = split(/\s+/,$line);
  278.         $swType = $args[1];
  279.         if ($swType eq "NET3") { $swType = "NET3/DSS1"; }
  280.         $countSPID = 0;
  281.         for ($i=0;$i<=$#args;$i++) {
  282.         if ($args[$i] eq "-s") { 
  283.             $spid[$countSPID] = $args[$i+1];
  284.             $countSPID++; 
  285.         }
  286.         }
  287.     }
  288.     }
  289.     close(IN);
  290.  
  291.     open(IN,"< $confS");
  292.     while(<IN>) {
  293.     @items = split(/\s+/);
  294.     if (substr($items[0],0,1) eq '#') { next; }
  295.     if ($items[2] eq 'ISDN') { 
  296.         $nme = $items[0];
  297.         $items[6] =~ /.*\](\w+)$/;
  298.         $phone = $1;
  299.     }
  300.     }
  301.     close(IN);
  302. }
  303.